package com.ruoyi.web.controller.bus.appletsController;

import com.ruoyi.bus.constant.UserTypeEnum;
import com.ruoyi.bus.service.IApiService;
import com.ruoyi.bus.vo.ChangeDriverPlan;
import com.ruoyi.bus.vo.LoginVo;
import com.ruoyi.bus.vo.RegisterVo;
import com.ruoyi.bus.vo.SiteInfo;
import com.ruoyi.bus.wechat.WechatApi;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Description 司机用户api接口
 * @Author caiyanshan
 * @Date 2021/4/15 8:46
 * @Param
 * @Return
 */
@Slf4j
@RestController
@RequestMapping("/driver")
public class DriverUserApiController extends BaseController {
  
  @Autowired
  private IApiService apiService;
  
  /**
   * @Description 登录功能
   * @Author caiyanshan
   * @Date 2021/4/15 14:24
   * @Param []
   * @Return com.ruoyi.common.core.domain.AjaxResult
   */
  @PostMapping("login")
  public AjaxResult login(@RequestBody LoginVo loginVo){
    loginVo.setUserType(UserTypeEnum.Driver_User.ordinal());//司机用户
    return apiService.login(loginVo);
  }
  
  /**
   * @Description 注册功能
   * @Author caiyanshan
   * @Date 2021/4/15 14:24
   * @Param []
   * @Return com.ruoyi.common.core.domain.AjaxResult
   */
  @PostMapping("register")
  @Log(title = "司机端注册", businessType = BusinessType.INSERT)
  public AjaxResult register(@Valid @RequestBody RegisterVo registerVo){
    registerVo.setUserType(UserTypeEnum.Driver_User.ordinal());//普通用户
    return apiService.register(registerVo);
  }
  
  @GetMapping("listPlanRecord")
  public AjaxResult listPlanRecord(@RequestParam Integer planStatus){
    return apiService.listPlanRecord(planStatus);
  }
  
  @GetMapping("getPlanDetails")
  public AjaxResult getPlanDetails(@RequestParam Long planId){
    return apiService.getPlanDetails(planId);
  }
  
  @GetMapping("reportSite")
  public AjaxResult reportSite(@RequestParam Long routeId, @RequestParam Long siteId, @RequestParam String driveTime){
    return apiService.reportSite(routeId, siteId, driveTime);
  }

  /**
   * 首页通知消息
   * @return
   */
  @GetMapping("listHomeNoticeData")
  public AjaxResult listHomeNoticeData(){
    return AjaxResult.success(apiService.listHomeNoticeData());
  }

  @GetMapping("listHomePlanRecord")
  public AjaxResult listHomePlanRecord(){
    return apiService.listHomePlanRecord();
  }

  /**
   * 通知详情
   * @param noticeId
   * @return
   */
  @GetMapping("getNoticeDetail")
  public AjaxResult getNoticeDetail(@RequestParam Long noticeId){
    return apiService.getNoticeDetail(noticeId);
  }
  
  /**
   * @Description 用户对应参数为1
   * @Author caiyanshan
   * @Date 2021/4/23 14:56
   * @Param []
   * @Return com.ruoyi.common.core.domain.AjaxResult
   */
  @GetMapping("jsCodeToSession")
  public AjaxResult jsCodeToSession(String jsCode){
    Integer type = 1;
    return WechatApi.getOpenIdByCode(jsCode, type);
  }
  
  /**
   * @Description 司机端发车
   * @Author caiyanshan
   * @Date 2021/4/24 13:04
   * @Param []
   * @Return com.ruoyi.common.core.domain.AjaxResult
   */
  @GetMapping("sendCar")
  public AjaxResult sendCar(@RequestParam Long busId, @RequestParam String driveTime){
    return apiService.sendCar(busId, driveTime);
  }
  
  /**
   * @Description 司机端结束行程
   * @Author caiyanshan
   * @Date 2021/4/24 14:10
   * @Param [busId, driveTime]
   * @Return com.ruoyi.common.core.domain.AjaxResult
   */
  @GetMapping("overCar")
  public AjaxResult overCar(@RequestParam Long busId, @RequestParam String driveTime){
    return apiService.overCar(busId, driveTime);
  }
  
  @PostMapping("reportSiteInfo")
  public AjaxResult reportSiteInfo(@RequestBody @Valid SiteInfo siteInfo){
    return apiService.reportSiteInfo(siteInfo);
  }
  
  @GetMapping("myRoute")
  public AjaxResult myRoute(){
    return apiService.myRoute();
  }

  /**
   * 换司机
   * @param changeDriver
   * @return
   */
  @PostMapping("changeDriver")
  public AjaxResult changeDriver(@RequestBody @Valid ChangeDriverPlan changeDriver){
    return apiService.changeDriverPlan(changeDriver);
  }

  /**
   * 可以更换司机用户列表
   * @return
   */
  @GetMapping("listChangeDriver")
  public AjaxResult listChangeDriver(){
    return apiService.listChangeDriver();
  }
}
